import numpy as np
class DSP:
    @staticmethod
    def cycle_corr(seq1, seq2, r):
        res = np.zeros(len(r), dtype=complex)
        conj_seq2 = np.conj(seq2)
        shift_seq2 = np.zeros(conj_seq2.shape,dtype=complex)
        
        c = 0
        for s in r:
            if s!=0:
                shift_seq2[s:] = conj_seq2[:-s]
                shift_seq2[:s] = conj_seq2[-s:]
            else:
                shift_seq2[:]  = conj_seq2[:]
            res[c] = np.dot(seq1,shift_seq2)
            c += 1
        return res
    
    @staticmethod
    def corr(seq1, seq2, r):
        res = np.zeros(len(r), dtype=complex)
        length = seq2.shape[0]
        conj_seq2 = np.conj(seq2)
        
        c = 0
        for s in r:
            shift_seq2 = np.zeros(length,dtype=complex)
            if s<0:
                shift_seq2[:s] = conj_seq2[-s:]
            else:
                shift_seq2[s:] = conj_seq2[:-s]
            res[c] = np.dot(seq1,shift_seq2)
            c += 1
        return res
